﻿namespace Baggr.FeedParser.Atom
{
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Xml.Serialization;

    /// <summary>
    /// The "atom:generator" element’s content identifies the agent used to
    /// generate a feed, for debugging and other purposes.
    /// </summary>
    [Serializable]
    [DebuggerStepThrough]
    [DesignerCategory("code")]
    [XmlType(Namespace = "http://www.w3.org/2005/Atom")]
    public class AtomGenerator
    {
        /// <summary>
        /// IRI reference [RFC3987]. When dereferenced, the resulting
        /// URI (mapped from an IRI, if necessary) SHOULD produce a
        /// representation that is relevant to that agent
        /// </summary>
        [XmlIgnore]
        public Uri Uri { get; set; }

        /// <summary>
        /// Version of the generating agent.
        /// </summary>
        [XmlAttribute("version")]
        public string Version { get; set; }

        /// <summary>
        /// The generating agent.
        /// </summary>
        [XmlText]
        public string Value { get; set; }

        [XmlAttribute("uri", DataType = "anyURI")]
        public string UriAsString
        {
            get
            {
                return Uri.ToString();
            }
            set
            {
                if (value == null)
                    Uri = null;
                else
                    Uri = new Uri(value);
            }
        }
    }
}
